GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#2835)
by
unknown
06:01
created

$.fn.symphonyDrawer   C

Complexity

Conditions 9
Paths 48

Size

Total Lines 87

Duplication

Lines 87
Ratio 100 %

Importance

Changes 0
Metric Value
cc 9
c 0
b 0
f 0
nc 48
nop 3
dl 87
loc 87
rs 5.3053

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
/**
2
 * @package assets
3
 */
4
5
(function($, Symphony) {
6
	'use strict';
7
8
	/**
9
	 * Drawers are hidden areas in the backend that are used to
10
	 * display additional content on request. There are three different
11
	 * types of drawers: horizontal, vertical left and vertical right.
12
	 *
13
	 * @name $.symphonyDrawer
14
	 * @class
15
	 *
16
	 * @param {Object} options An object specifying containing the attributes specified below
17
	 * @param {Integer} [options.verticalWidth=300] Width of the vertical drawers
18
	 * @param {String} [options.speed='fast'] Animation speed
19
	 *
20
	 * @example
21
22
			$('.drawer').symphonyDrawer();
23
	 */
24
	$.fn.symphonyDrawer = function(options) {
25
		var objects = this,
26
			wrapper = $('#wrapper'),
27
			contents = $('#contents'),
28
			form = contents.find('> form'),
29
			settings = {
30
				verticalWidth: 300,
31
				speed: 'fast'
32
			};
33
34
		$.extend(settings, options);
35
36
	/*-------------------------------------------------------------------------
37
		Events
38
	-------------------------------------------------------------------------*/
39
40
		// Expand drawer
41 View Code Duplication
		objects.on('expand.drawer', function expand(event, speed, stay) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
42
			var drawer = $(this),
43
				position = drawer.data('position'),
44
				buttons = $('.button.drawer'),
45
				button = buttons.filter('[href="#' + drawer.attr('id') + '"]'),
46
				samePositionButtons = buttons.filter('.' + position),
47
				context = drawer.data('context') ? '.' + drawer.data('context') : '',
48
				height = getHeight();
49
50
			drawer.trigger('expandstart.drawer');
51
52
			speed = (typeof speed === 'undefined' ? settings.speed : speed);
0 ignored issues
show
Comprehensibility Best Practice introduced by
This re-assigns to the parameter speed. Re-assigning to parameters often makes code less readable, consider introducing a new variable instead.
Loading history...
53
			stay = (typeof stay === 'undefined' ? false : true);
0 ignored issues
show
Comprehensibility Best Practice introduced by
This re-assigns to the parameter stay. Re-assigning to parameters often makes code less readable, consider introducing a new variable instead.
Loading history...
Unused Code introduced by
The assignment to variable stay seems to be never used. Consider removing it.
Loading history...
54
55
			// update button state
56
			samePositionButtons.removeClass('selected');
57
58
			// Close opened drawers from same region
59
			$('.drawer.' + position).filter(function() {
60
				return $(this).data('open');
61
			}).trigger('collapse.drawer', [speed, true]);
62
63
			if (position === 'vertical-left') {
64
				drawer.css({
65
					width: 0,
66
					height: height,
67
					display: 'block'
68
				})
69
				.animate({
70
					width: settings.verticalWidth
71
				}, {
72
					duration: speed,
73
					step: function(now){
74
						form.css('margin-left', now + 1); // +1px right border
75
					},
76
					complete: function() {
77
						form.css('margin-left', settings.verticalWidth + 1); // +1px right border
78
						drawer.trigger('expandstop.drawer');
79
					}
80
				});
81
			}
82
			else if (position === 'vertical-right') {
83
				drawer.css({
84
					width: 0,
85
					height: height,
86
					display: 'block'
87
				})
88
				.animate({
89
					width: settings.verticalWidth
90
				}, {
91
					duration: speed,
92
					step: function(now){
93
						form.css('margin-right', now + 1); // +1px left border
94
					},
95
					complete: function() {
96
						form.css('margin-right', settings.verticalWidth + 1); // +1px right border
97
						drawer.trigger('expandstop.drawer');
98
					}
99
				});
100
			}
101
			else if (position === 'horizontal') {
102
				drawer.animate({
103
					height: 'show'
104
				}, {
105
					duration: speed,
106
					complete: function() {
107
						drawer.trigger('expandstop.drawer');
108
					}
109
				});
110
			}
111
112
			button.addClass('selected');
113
114
			// store state
115
			if(Symphony.Support.localStorage === true) {
116
				// Put in a try/catch incase we exceed storage space
117
				try {
118
					window.localStorage['symphony.drawer.' + drawer.attr('id') + context] = 'opened';
119
				}
120
				catch(e) {
121
					window.onerror(e.message);
122
				}
123
			}
124
125
			wrapper.addClass('drawer-' + position);
126
			drawer.data('open', true);
127
		});
128
129
		// Collapse drawer
130 View Code Duplication
		objects.on('collapse.drawer', function collapse(event, speed, stay) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
131
			var drawer = $(this),
132
				position = drawer.data('position'),
133
				buttons = $('.button.drawer'),
134
				button = buttons.filter('[href="#' + drawer.attr('id') + '"]'),
135
				context = drawer.data('context') ? '.' + drawer.data('context') : '';
136
137
			drawer.trigger('collapsestart.drawer');
138
139
			speed = (typeof speed === 'undefined' ? settings.speed : speed);
0 ignored issues
show
Comprehensibility Best Practice introduced by
This re-assigns to the parameter speed. Re-assigning to parameters often makes code less readable, consider introducing a new variable instead.
Loading history...
140
			stay = (typeof stay === 'undefined' ? false : true);
0 ignored issues
show
Comprehensibility Best Practice introduced by
This re-assigns to the parameter stay. Re-assigning to parameters often makes code less readable, consider introducing a new variable instead.
Loading history...
141
142
			// update button state
143
			button.removeClass('selected');
144
145
			if (position === 'vertical-left') {
146
				drawer.animate({
147
					width: 0
148
				}, {
149
					duration: speed,
150
					step: function(now){
151
						if (!stay) {
152
							form.css('margin-left', now);
153
						}
154
					},
155
					complete: function() {
156
						drawer.css({
157
							display: 'none'
158
						})
159
						.trigger('collapsestop.drawer');
160
					}
161
				});
162
			}
163
			else if (position === 'vertical-right') {
164
				drawer.animate({
165
					width: 0
166
				}, {
167
					duration: speed,
168
					step: function(now){
169
						if (!stay) {
170
							form.css('margin-right', now);
171
						}
172
					},
173
					complete: function() {
174
						drawer.css({
175
							display: 'none'
176
						})
177
						.trigger('collapsestop.drawer');
178
					}
179
				});
180
			}
181
			else if (position === 'horizontal') {
182
				drawer.animate({
183
					height: 'hide'
184
				}, {
185
					duration: speed,
186
					complete: function() {
187
						drawer.trigger('collapsestop.drawer');
188
					}
189
				});
190
			}
191
192
			// store state
193
			if(Symphony.Support.localStorage === true) {
194
				// Put in a try/catch incase we exceed storage space
195
				try {
196
					window.localStorage['symphony.drawer.' + drawer.attr('id') + context] = 'closed';
197
				}
198
				catch(e) {
199
					window.onerror(e.message);
200
				}
201
			}
202
203
			wrapper.removeClass('drawer-' + position);
204
			drawer.data('open', false);
205
		});
206
207
		// Resize drawers
208
		$(window).on('resize.drawer load.drawer', function() {
209
			var height = getHeight();
210
			objects.filter('.vertical-left, .vertical-right').css('height', height);
211
		});
212
213
	/*-------------------------------------------------------------------------
214
		Utilities
215
	-------------------------------------------------------------------------*/
216
217
		var getHeight = function() {
218
			var height = Math.max(window.innerHeight - contents[0].offsetTop - 1, contents[0].clientHeight);
219
220
			return height;
221
		};
222
223
	/*-------------------------------------------------------------------------
224
		Initialisation
225
	-------------------------------------------------------------------------*/
226
227
		objects.each(function drawers() {
228
			var drawer = $(this),
229
				button = $('.button.drawer[href="#' + drawer.attr('id') + '"]'),
230
				context = drawer.data('context') ? '.' + drawer.data('context') : '',
231
				storedState;
232
233
			// Initial state
234
			if (drawer.data('default-state') === 'opened') {
235
				drawer.data('open', true);
236
			}
237
			// Restore state
238
			if (Symphony.Support.localStorage === true) {
239
				storedState = window.localStorage['symphony.drawer.' + drawer.attr('id') + context];
240
				if (storedState === 'opened') {
241
					drawer.data('open', true);
242
				}
243
				else if (storedState === 'closed') {
244
					drawer.data('open', false);
245
				}
246
			}
247
248
			// Click event for the related button
249
			button.on('click.drawer', function(event) {
250
				event.preventDefault();
251
				drawer.trigger(!drawer.data('open') ? 'expand.drawer': 'collapse.drawer');
252
			});
253
254
			// Initially opened drawers
255
			if (drawer.data('open')) {
256
				drawer.trigger('expand.drawer', [0]);
257
			} else {
258
				drawer.trigger('collapse.drawer', [0, true]);
259
			}
260
		});
261
262
	/*-----------------------------------------------------------------------*/
263
264
		return objects;
265
	};
266
267
})(window.jQuery, window.Symphony);
268